<?php
require 'settings.php';
require 'db.php';

$pl_id = $_POST['pricelist_id'];
?>

<html>
<head>
<title><?php echo $corp_name?> Industry Manager - Edit pricelist "<?php echo $pl_name ?>"</title>

<style type="text/css">
table, th, td
{
border: 1px solid black;
border-collapse: collapse;
padding: 5px;
}
</style>

</head>
<body>

<?php
//$pricelist_get_data = $db_corp->prepare( "SELECT pricelist_name, pricelist_last_update, markup_over_buildcost, replacement_discount, round_to, production_location_id FROM pricelists WHERE pricelist_ID = ?" );

$pricelist_get_data->bind_param( 'i', $pl_id );
$pricelist_get_data->bind_result( $pl_name, $pl_upd, $pl_markup, $pl_discount, $pl_round, $pl_loc_id );
$pricelist_get_data->execute();
$pricelist_get_data->fetch();
$pricelist_get_data->close();

?>
<h1 class=c_page_title>Edit pricelist "<?php echo $pl_name ?>"</h1>

<form id="edit_pricelist" action="edit_pricelist1.php" method="post">
<input type="hidden" name="pricelist_id" value="<?php echo $pl_id ?>" />

<label>Name of the pricelist:</label>
<input type="text" name="pricelist_name" value="<?php echo $pl_name ?>" />

<br />
<label>Markup:</label>
<input type="text" name="pricelist_markup" value="<?php echo $pl_markup ?>" />
<label>%</label>

<br />
<label>Replacement discount:</label>
<input type="text" name="pricelist_replacement_discount" value="<?php echo $pl_discount ?>" />
<label>%</label>
<br />

<label>Round values to:</label>
<input type="text" name="pricelist_round_to" value="<?php echo $pl_round ?>" />

<br />
<label>Production faclity for this list:</label>
<select name="pricelist_facility">

<?php
	$get_all_facilities_names->bind_result( $fac_id, $fac_name );
	$get_all_facilities_names->execute();
	while( $get_all_facilities_names->fetch() )
	{
		if( $fac_id == $pl_loc_id )
		{
			$output = '<option selected="selected" value="'.$fac_id.'">'.$fac_name.'</option>';
		}
		else
		{
			$output = '<option value="'.$fac_id.'">'.$fac_name.'</option>';
		}
		echo $output;
	}
	$get_all_facilities_names->close();
?>
</select>
<br />
<input type="submit" value="Save changes" />
</form>


<br />

<a href="view_pricelists.php">View pricelists</a><br />
<a href="index.php">Back to main screen</a>
</body>
</html>